package com.jt.tenant.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.amap.api.maps.AMap;
import com.amap.api.maps.CameraUpdate;
import com.amap.api.maps.CameraUpdateFactory;
import com.amap.api.maps.LocationSource;
import com.amap.api.maps.TextureMapView;
import com.amap.api.maps.model.LatLng;
import com.amap.api.maps.model.Marker;
import com.amap.api.maps.model.MarkerOptions;
import com.jt.tenant.R;
import com.jt.tenant.adapter.DetectionAdapter;
import com.jt.tenant.app.JTApplication;
import com.jt.tenant.conn.GetDiagnosticCar;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * Created by Administrator on 2016/3/11.
 */
public class DetectionResultActivity extends JTActivity implements View.OnClickListener{

    private TextView title_name;

    private LinearLayout mLinYes,mLinNo;

    private ListView mList;

    private TextView mBtn;

    private DetectionAdapter mAdapter;

    private List<GetDiagnosticCar.Detection> list = new ArrayList<>();

    private String flag = "";

    private TextView mTextScore;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_detection_result);

        getData();

        init_view();
    }

    private void getData(){

        Intent intent = getIntent();

        Bundle bundle = intent.getExtras();

        flag = bundle.getString("flag");

        if(flag.equals("1")){

            list.addAll((Collection<? extends GetDiagnosticCar.Detection>) bundle.getSerializable("list"));

        }

    }

    private void init_view() {

        (title_name = (TextView) findViewById(R.id.tv_detection_result_title)).setText("检测结果");

        mLinNo = (LinearLayout) findViewById(R.id.lin_det);

        mLinYes = (LinearLayout) findViewById(R.id.lin_det_yes);

        mList = (ListView) findViewById(R.id.list_det);

        (mBtn = (TextView) findViewById(R.id.text_det_commit)).setOnClickListener(this);

        mTextScore = (TextView) findViewById(R.id.detection_title_score);

        mTextScore.setText(JTApplication.jtPreferences.readScore());

        mAdapter = new DetectionAdapter(DetectionResultActivity.this,list);

        if(flag.equals("0")){

            mLinNo.setVisibility(View.GONE);

            mList.setVisibility(View.GONE);

            mLinYes.setVisibility(View.VISIBLE);

            mBtn.setText("确定");

        }else{

            mLinYes.setVisibility(View.GONE);

            mLinNo.setVisibility(View.VISIBLE);

            mList.setVisibility(View.VISIBLE);

            mBtn.setText("查看完整检测报告");

        }

        mList.setAdapter(mAdapter);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.text_det_commit:

                if(flag.equals("0")){

                    finish();

                }else{

                    startActivity(new Intent(this,DiagnosisActivity.class));

                }

        }


    }
}
